﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace GameUtils
{
    public static class MathUtils
    {
        #region Constants
        public const float FLOAT_EPSILON = 10e-5f;
        #endregion

        #region Methods
        public static int GetLimitedInt(int pValue, int pMin, int pMax)
        {
            return Math.Min(Math.Max(pMin, pValue), pMax);
        }

        public static Vector2 ConvertToSquareCoordinates(float pRadius, float pAngleRad)
        {
            float x = (float)(pRadius * Math.Cos(pAngleRad));
            float y = (float)(pRadius * Math.Sin(pAngleRad));
            return new Vector2(x, y);
        }

        public static float WrapAngleRad(float pAngle)
        {
            return ((pAngle % MathHelper.TwoPi) + MathHelper.TwoPi) % MathHelper.TwoPi;
        }

        public static float LinearInterpolation(
            float pX,
            float pX1,
            float pX2,
            float pY1,
            float pY2)
        {
            return pY1 + (pX - pX1) / (pX2 - pX1) * (pY2 - pY1);
        }
        #endregion
    }
}